﻿// see http://www.hand-interactive.com/js/mdetect.js
// http://www.blog.highub.com/mobile-2/a-fix-for-iphone-viewport-scale-bug/
//http://developer.apple.com/library/safari/#documentation/appleapplications/reference/SafariHTMLRef/Articles/MetaTags.html
//http://www.quirksmode.org/mobile/viewports2.html
//http://www.iphonewebdev.com/faq.shtml


function laostmdDetectFireFox()
{
   return (laostmdUASearch("firefox"));
}


function gestureStart() 
{
	var metas = document.getElementsByTagName('meta');
	var i;
	for (i=0; i<metas.length; i++)
	{
		if (metas[i].name == "viewport") 
		{
			metas[i].content = "width=device-width, minimum-scale=0.25, maximum-scale=1.6";
		}
	}	
}

function initIphone()
{
	if (laostmdDetectIphone()) 
	{	
		document.addEventListener("gesturestart", gestureStart, false);
	}
}


function laostmdDetectMobile()
{
   return (laostmdDetectIphone() || laostmdDetectAndroid());
}

function laostmdDetectIphone()
{
   if (!laostmdUASearch("iphone"))
       return false;
      
   //The iPad and iPod Touch say they're an iPhone! So let's disambiguate.
   return (!laostmdDetectIpad() && !laostmdDetectIpod());
}

// Detects if the current device is an Android.
function laostmdDetectAndroid()
{
   return (laostmdUASearch("android"));
}

// Detects if the current device is an iPod Touch.
function laostmdDetectIpod()
{
   return (laostmdUASearch("ipod"));
}

// Detects if the current device is an iPad tablet.
function laostmdDetectIpad()
{
   return (laostmdUASearch("ipad") && laostmdDetectWebkit()); 
}

// Detects if the current device is an iPhone or iPod Touch.
function laostmdDetectIphoneOrIpod()
{
   //We repeat the searches here because some iPods 
   //may report themselves as an iPhone, which is ok.
   return (laostmdDetectIphone() || laostmdDetectIpod());
}

// Detects if the current browser is based on WebKit.
function laostmdDetectWebkit()
{
   return (laostmdUASearch("webkit"));
}

// Searchfield helper
function laostmdUASearch(field)
{
   return (navigator.userAgent.toLowerCase().search(field) != -1);
}
